/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/
/*!
 \file  dhl-struct.h
 \brief DHL Communication Structs

 * This file contains structures that correspond to NetUAS (MHL or DHL) payloads.
 * In NetUAS terms, these are capabilities.
 * This file was created to make building debug/house keeping/high speed/data
 * packets much cleaner and easier.
*/

#ifndef __DHLSTRUCT_H
#define __DHLSTRUCT_H

#include "dhl-config.h"

#define CUPIC_LED0_MASK (0x01)
#define CUPIC_LED1_MASK (0x02)
#define CUPIC_LED2_MASK (0x04)
#define CUPIC_LED3_MASK (0x08)

#define CAP_ATTRIBUTES    (10)

typedef struct {
	cu_uint_t parent;
	cu_uchar_t requesting;
} ATTRIBUTE_PACKED DHL_Custody_t;


typedef struct {
    cu_uchar_t id;
    cu_uchar_t sub_system_id;
    cu_uint_t commands;      // must at least 16 bits to hold all possible sub_system_id types
    cu_uint_t streams;
    cu_uchar_t attributes[CAP_ATTRIBUTES]; // FIXME: find a way to use attributes
} ATTRIBUTE_PACKED DHL_Capabilities_t;


typedef struct {
  cu_uchar_t id;
  cu_uint_t client;
  cu_uchar_t start;
} ATTRIBUTE_PACKED DHL_StreamRequest_t;


typedef struct {
    cu_uchar_t LEDS;
} ATTRIBUTE_PACKED DHL_LED_t;


typedef struct {
  cu_uint_t     packet_number;
  cu_uint_t     heading;
  cu_long_t     lon;
  cu_long_t     lat;
  cu_uint_t     palt_msw;       // Pressure Altitude is 3 bytes (wierd)
  cu_uchar_t    palt_lsb; 
  cu_uint_t     roll_est_g;     // Gyro Based Roll angle estimate
  cu_uchar_t    flight_status;
  cu_uint_t     helix_top_alt;
  cu_uint_t     helix_btm_alt;
  cu_uint_t     cmd_alt;
  cu_uint_t     pitot_as;       // divide by 10 to get degrees
  cu_uint_t     gy_temp;        // divide by 10 to get degrees
  cu_uint_t     throttle;        // divide by 10 to get degrees
  cu_uint_t     alt;
  cu_uint_t     speed;       // speed? lyapunov
} ATTRIBUTE_PACKED DHL_DebugPacket_t;


typedef struct {
  cu_uint_t     packet_number;
  cu_uint_t     palt_msw; // Pressure altitude is 3 bytes
  cu_uint_t     palt_lsb;
  cu_uint_t     tow;      // ?
  cu_uchar_t    spi[24]; // ?
  cu_uint_t     pitot_as; // pitot airspeed
} ATTRIBUTE_PACKED DHL_DataPacket_t;


typedef struct {
  cu_uint_t     packet_number;
  cu_uint_t     battery_voltage;
  cu_long_t     x_loiter_center;
  cu_long_t     y_loiter_center;
  cu_uint_t     r_d;
  cu_uchar_t    ascent_rate;
  cu_uchar_t    descent_rate;
  cu_uint_t     r_bound;
  cu_uint_t     bound_alt;
  cu_long_t     x_bound_center;
  cu_long_t     y_bound_center;
  cu_uint_t     version_num;
  cu_uchar_t    flight_term_status;
  cu_uchar_t    incoming_RSSI;
  cu_uint_t     time_left;
} ATTRIBUTE_PACKED DHL_HouseKeeping_t;


typedef struct {
  cu_uint_t     data[20];
  cu_uint_t     tow; // on ground multiply by 256 then divide by 1000 to get seconds
  cu_uint_t     packet_number;
  cu_uchar_t    motor_on;
} ATTRIBUTE_PACKED DHL_HighSpeed_t;

#endif
